package com.bhkj.pdjhbgnewproject.app;

import android.app.Application;
import android.app.Notification;
import android.content.Context;

import com.bhkj.pdjhbgnewproject.R;
import com.bhkj.pdjhbgnewproject.common.contanct.Contacts;
import com.bhkj.websocketlibrary.socketio.SocketEvent;
import com.bhkj.websocketlibrary.ws.WsConfig;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.CrashUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.Utils;
import com.zhouyou.http.EasyHttp;

import cn.jpush.android.api.BasicPushNotificationBuilder;


public class App extends Application {
    private static Context ctx;

    @Override
    public void onCreate() {
        super.onCreate();
        ctx = this;
        //极光推送初始化
//        JPushInterface.init(this);
//        JPushInterface.setDebugMode(false);
//        JPushInterface.clearAllNotifications(this);
//        JPushInterface.setDefaultPushNotificationBuilder(setPushNotSound());
        //网络框架
        EasyHttp.init(this);
        EasyHttp.getInstance().setBaseUrl(Contacts.BASE_URL).setRetryDelay(0);
        Utils.init(this);
        //app崩溃搜集日志保存在本地
        CrashUtils.init(new CrashUtils.OnCrashListener() {
            @Override
            public void onCrash(String crashInfo, Throwable e) {
                AppUtils.relaunchApp(true);
            }
        });
        //关闭log
        LogUtils.getConfig().setLogSwitch(true);
//        CrashReport.initCrashReport(this, "7467511dcb", false);

        WsConfig.getInstance().setUrl("http://192.168.1.108:9999")
                .setQuery("ip=" + getString(R.string.deptId) + NetworkUtils.getIPAddress(true) + "&roomid=1")
                .setLoginType(SocketEvent.WINDOWINFO)
                .setLogoutType(SocketEvent.QLOGOUT)
                .setWindowStatusType(SocketEvent.QWINDOWSTATUS);

    }

    public static Context getCtx() {
        return ctx;
    }

    /**
     * 极光推送消息没有语音提示
     *
     * @return BasicPushNotificationBuilder
     */
    private BasicPushNotificationBuilder setPushNotSound() {
        BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(this);
        builder.notificationDefaults = Notification.DEFAULT_LIGHTS;
        return builder;
    }

}
